<?php
error_reporting(E_ALL ^ E_NOTICE);

set_time_limit(0);
date_default_timezone_set("PRC"); //timezone

$db1=mysql_connect("192.168.0.17","root","root"); 
mysql_select_db('faithwar',$db1); 

$db2=mysql_connect('114.80.213.44','triniti','triniti'); 
mysql_select_db('faithwar',$db2); 

$update_query = mysql_query("SELECT logDate, logInfo FROM tbiapa UNION SELECT logDate, logInfo FROM tbiapb ORDER BY logDate ASC",$db2);

while($update = mysql_fetch_array($update_query))
{
   $arr = json_decode($update[logInfo], true);
    $id =  $arr["id"];
    $id2 = $arr["money"];
    $s = 0;
    foreach ((array) $arr as $item => $value) {   //Warning: Invalid argument supplied for foreach
        $s = count($value); //
    }
    for ($i = 0; $i < $s; $i++) {
         $deviceid = $id;
         $money = $id2;

   mysql_query("TRUNCATE TABLE faithwar.tbiap");
   mysql_query("REPLACE INTO tbiap ( logDate,date,deviceid,money) 
                    VALUES('$update[logDate]','$update[logDate]','$deviceid','$money')",$db1) or die(mysql_error());
}
 }
 print "Import successful!<br>";

?>